//
//  BaseRequest.h
//  XJMCustomer
//
//  Created by Mr.hu on 2017/10/9.
//  Copyright © 2017年 Mr.hu. All rights reserved.
//

#import <Foundation/Foundation.h>

#import "BaseUrl.h"
#import "XJAFNCliect.h"
#define HTTP_GET_Request @"GET"
#define HTTP_POST_Request @"POST"
#define HTTP_PUT_Request @"PUT"
#define HTTP_DELETE_Request @"DELETE"

#define REQUEST_DEFAULT_TIME_OUT 15

@class BaseRequest;

@protocol BaseRequestDelegate <NSObject>

@optional
//请求失败
- (void)request:(BaseRequest *)request failedWithError:(NSError *)error;
//请求延时
- (void)requestTimeOut:(BaseRequest *)request;

@required
//请求成功
- (void)request:(BaseRequest *)request successLoadData:(NSMutableDictionary *)dic;
//
- (void)request:(BaseRequest *)request failLoadDataWithErrorCode:(NSString *)errorCode;

@end

@interface BaseRequest : NSObject

@property (nonatomic)BOOL access;
@property (nonatomic,strong)NSMutableDictionary *agrs;  //key值
@property (nonatomic,strong)NSString *host;
@property (nonatomic,strong)NSString *requestMethod;  //分post和get
@property (nonatomic,strong) NSString *actionKey;

@property (nonatomic,weak)id <BaseRequestDelegate> delegate;

@property (nonatomic) NSTimeInterval timeOut; //default is 15s

//开始请求
- (void)start;
//取消请求
- (void)cancel;
//上传data
-(void)updateData:(NSData *)data;

//上传data
-(void)updateData:(NSData *)data Name:(NSString *)name;

//上传多张图片
-(void)updateImages:(NSArray *)images names:(NSArray *)names;

//
- (id)toArrayOrNSDictionary:(NSData *)jsonData;

@end
